<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品项目组列表')" />
    <th:block th:include="include :: layout-latest-css" />
</head>
<body class="gray-bg">

<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 项目列表
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#"  title="管理部门"><i class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="projectSelect" class="col-sm-10">
            </div>
        </div>
    </div>
</div>

<div class="ui-layout-center">

     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="text"  id="projectCode" name="projectCode" hidden />
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>部门名称：</label>
                                <input type="text" name="groupName"/>
                            </li>
                            <li>
                                <label>负责人：</label>
                                <input type="text" name="leader"/>
                            </li>
                            <li>
                                <label>联系电话：</label>
                                <input type="text" name="phone"/>
                            </li>
                            <li>
                                <label>邮箱：</label>
                                <input type="text" name="email"/>
                            </li>
                            <li>
                                <label>部门状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="-1">代码生成请选择字典属性</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="createForProject()" shiro:hasPermission="system:group:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:group:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:group:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:group:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> 展开/折叠
                </a>

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-tree-table"></table>
            </div>
        </div>
    </div>
</div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <script th:inline="javascript">

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            queryProjectList();
        });



        var addFlag = [[${@permission.hasPermi('system:group:add')}]];
        var editFlag = [[${@permission.hasPermi('system:group:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:group:remove')}]];
        var projectListFlag = [[${@permission.hasPermi('system:project:projectList')}]];
        var prefix = ctx + "system/group";

        /**
         * 打开创建界面
         * */
        function createForProject(){
            $.operate.add($("#projectCode").val())
        }

        /**
         * 查询项目列表清单
         */
        function queryProjectList()
        {
            var url = ctx + "system/project/projectList";
            $.ajax({
                url: url,
                data: {},
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                success: function (result) {
                    var len = result.length;
                    if(len>0)
                    {
                        var html = "";
                        for(var i=0;i<len;i++){
                            html+="  <div class=\"radio\">\n" +
                                "                    <label><input type=\"radio\" checked=\"\" value="+result[i].code+"  onclick=\"changeProject(this)\" >"+result[i].name+"</label>\n" +
                                "    </div>"
                        }
                        $("#projectSelect").html(html);
                    }
                }
            });
        }

        /**
         * 项目组列表
         */
        $(function() {
            var options = {
                code: "groupId",
                parentCode: "parentId",
                uniqueId: "groupId",
                expandAll: true,
                expandFirst: false,
                url: prefix + "/treeList",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                search:true,
                modalName: "产品项目组",
                columns: [{
                    field: 'selectItem',
                    radio: true
                },
                {
                    field: 'groupName', 
                    title: '项目组名称',
                    align: "left"
                },
                {
                    field: 'phone',
                    title: '联系电话',
                    align: "left"
                },
                {
                    field: 'email',
                    title: '邮箱',
                    align: "left"
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.groupId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.groupId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.treeTable.init(options);
        });

        /**
         * 切换项目进行列表数据变更
         * @param event
         */
        function changeProject(event)
        {
            $("#projectCode").val($(event).val());
            $.treeTable.search();
        }
    </script>
</body>
</html>